package controllers

import (
	"gdshop-font-api-go/app/request/CouponReq"
	"gdshop-font-api-go/app/service/CouponService"
	"gdshop-font-api-go/library/response"
	"gdshop-font-api-go/library/tools/token"
	"github.com/gogf/gf/net/ghttp"
)

type CouponController struct {
	*BaseController
}

func (c *CouponController) Init(r *ghttp.Request) *response.JsonResponse {
	memberId = token.GetLoginMemberId(r)
	if memberId < 1 {
		return response.FailByRequestMessage(r, "获取会员ID失败")
	}
	return response.SuccessByRequest(r)
}

func (c *CouponController) Index(r *ghttp.Request) *response.JsonResponse {
	//r.SetCtxVar("fanhui", fanhui) // 上下文
	var parames *CouponReq.Index
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = memberId
	return CouponService.Index(r.GetCtx(), parames)
}

func (c *CouponController) Receive(r *ghttp.Request) *response.JsonResponse {
	var parames *CouponReq.Receive
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = memberId
	return CouponService.Receive(r.GetCtx(), parames)
}

func (c *CouponController) My(r *ghttp.Request) *response.JsonResponse {
	var parames *CouponReq.My
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = memberId
	return CouponService.My(r.GetCtx(), parames)
}

func (c *CouponController) Details(r *ghttp.Request) *response.JsonResponse {
	return CouponService.Details(r)
}
